<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch">
      
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="" prop="serialCode">
              <el-input
                v-model="queryParams.serialCode"
                placeholder="申请编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="" prop="orgName">
              <el-input
                v-model="queryParams.orgName"
                placeholder="企业名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
           <el-col :span="8">
          <el-form-item label="" prop="projectName">
            <el-select v-model="queryParams.projectName" size="small" placeholder="应用项目" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.sys_project_name"
                :key="dict.value"
                :label="dict.label"
                :value="dict.label"
              />
            </el-select>
          </el-form-item>
      </el-col>
        
           <!-- <el-col :span="6">
          <el-form-item label="" prop="approvalStatus">
            <el-select v-model="queryParams.approvalStatus" size="small" placeholder="当前状态" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.approval_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
      </el-col> -->
           <el-col :span="8">
          <el-form-item label="" prop="overdueStatistics">
            <el-select v-model="queryParams.overdueStatistics" @change="changeSelect" size="small" placeholder="超期统计" style="width:100%" clearable>
              <el-option
                v-for="dict in dict.type.exceed_statistics"
                :key="dict.value"
                :label="dict.label"
                :value="dict.label"
              />
            </el-select>
          </el-form-item>
      </el-col>
        <el-col :span="8">
            <el-form-item label="" prop="daysOverdue">
               <el-input
                v-model="queryParams.daysOverdue"
                type="number"
                placeholder="超期 >= 天数"
                clearable
                :disabled="dayDisabled"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
        </el-col>
          <!-- <el-col :span="6">
            <el-form-item label="">
              <el-date-picker
                v-model="dateRange"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="创建开始日期"
                end-placeholder="创建结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col> -->
           
        </el-row>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :disabled="multiple"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:dict:remove']"
        >删除</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="typeList" @selection-change="handleSelectionChange" :default-sort = "{prop: 'createTime', order: 'descending'}">
      <el-table-column type="selection" width="55" align="center"  fixed/>
      <el-table-column type="index" width="55" align="center" label="序号" fixed />
      <el-table-column label="申请编号" align="center" prop="serialCode" width="200" fixed>
        <template slot-scope="scope">
          <el-link type="primary" @click="handleDetail(scope.row)">{{scope.row.serialCode}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="企业名称" align="center" prop="orgName" show-overflow-tooltip  width="200" fixed/>
     <el-table-column label="应用项目" align="center" prop="projectName" show-overflow-tooltip width="150"/>
        <el-table-column label="申请日期" sortable   align="center" prop="applyForTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyForTime) }}</span>
        </template>
      </el-table-column>
       <!-- <el-table-column label="当前状态" align="center" prop="status" width="150">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.approval_status" :value="scope.row.status"/>
        </template>
      </el-table-column> -->
       <el-table-column label="规定处理期限" align="center" prop="dueDateNum" width="150"/>
       <el-table-column label="实际处理天数" align="center" prop="totalTerm" width="150"/>
     <el-table-column label="规定处理期限超期天数" align="center" prop="totalTermOverdue" width="200" />
      <el-table-column label="项目部受理人初审超期日期" align="center" prop="xmbslrcsOverdueDate" width='200' />
      <el-table-column label="项目部受理人初审超期天数" align="center" prop="xmbslrcsOverdueDay" width='200' />
      <el-table-column label="项目部领导复审超期日期" align="center" prop="xmbldfsOverdueDate" width='200' />
      <el-table-column label="项目部领导复审超期天数" align="center" prop="xmbldfsOverdueDay" width='200' />
      <el-table-column label="科技处领导审核超期日期" align="center" prop="kjcldshOverdueDate" width='200' />
      <el-table-column label="科技处领导审核超期天数" align="center" prop="kjcldshOverdueDay" width='200' />
      <el-table-column label="科技处业务人员经办超期日期" align="center" prop="kjcywryjbOverdueDate" width='200' />
      <el-table-column label="科技处业务人员经办超期天数" align="center" prop="kjcywryjbOverdueDay" width='200' />
      <el-table-column label="分中心人员处理超期日期" align="center" prop="fzxryclOverdueDate" width='200' />
      <el-table-column label="分中心人员处理超期天数" align="center" prop="fzxryclOverdueDay" width='200' />
      <el-table-column label="外部公司人员安装超期日期" align="center" prop="wbgsryazOverdueDate" width='200' />
      <el-table-column label="外部公司人员安装超期天数" align="center" prop="wbgsryazOverdueDay" width='200' />
      <el-table-column label="归档日期" align="center" prop="archiveDate" width='200' />






      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
          >查看详情</el-button>
        
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :pageSizes=[10,20]
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listTrace,listTraceExport} from '@/api/businessModule/track.js'
// import { listType, getType, delType, addType, updateType, } from "@/api/system/dict/type";
import { saveAs } from 'file-saver'
export default {
  name: "apply",
  dicts:['sys_project_name','approval_status','exceed_statistics'],
  data() {
    return {
      dayDisabled:true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      dictNames:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      typeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serialCode:null,
        orgName:null,
        projectName:null,
        overdueStatistics:null,
        daysOverdue:null
      },
      // 表单参数
      form: {},
      // 表单校验
     
    };
  },
  created() {
    this.getList();
  },
  methods: {
    changeSelect(val){
      if(val!==''){
        this.dayDisabled=false
      } else {
          this.queryParams.daysOverdue = ''
          this.dayDisabled=true
      }
      
      
    },
    /** 查询字典类型列表 */
    getList() {
      
      if(this.queryParams.overdueStatistics&&!this.queryParams.daysOverdue){
        return this.$message.warning('请输入超期天数')
      }else if(this.queryParams.daysOverdue&&!this.queryParams.overdueStatistics){
         this.queryParams.daysOverdue=null
      }else if(this.queryParams.daysOverdue&&this.queryParams.overdueStatistics==''){
         this.queryParams.daysOverdue=null
      }
      this.loading = true;
      listTrace(this.queryParams).then(response => {
          this.typeList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
       
      };
      this.resetFormData("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.dayDisabled = true
      this.resetFormData("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
   
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.serialCode)
      this.dictNames = selection.map(item => item.dictName)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    handleDetail(row){
      this.$router.push({
        path:'/statistics/trackDetail',
        query:{
          serialCode:row.serialCode,
         
        }
      })
      
    },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const dictIds = row.dictId || this.ids;
    //   const dictNames = row.dictName || this.dictNames;
    //   this.$modal.confirm('是否确认删除字典编号为"' + dictNames + '"的数据项？').then(function() {
    //     return delType(dictIds);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // },
    /** 导出按钮操作 */
    handleExport() {
      listTraceExport({
        serialCode:this.ids.join()
      }).then(res=>{
        const blob = new Blob([res])
        saveAs(blob, '申请流程跟踪数据.xlsx')
      })
      // this.download('system/workflow/process/listTraceExport', {
      //   serialCode:this.ids.join()
      // }, `type_${new Date().getTime()}.xlsx`)
    },

  }
};
</script>